package com.slw.emergency.controller;

import com.slw.emergency.model.*;
import com.slw.emergency.service.EpidemicService;
import com.slw.emergency.service.OverseaEpidemicService;
import com.slw.emergency.service.QueryService;
import com.slw.emergency.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/epidemic")
public class EpidemicController {

    @Autowired
    private EpidemicService epidemicService;

    @Autowired
    private QueryService queryService;

    @Autowired
    private OverseaEpidemicService overseaEpidemicService;

    //获取全国疫情数据、新增数据
    @GetMapping("/china")
    public RespChinaEpidemic getChinaEpidemic(){
        Date date=new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String todayDate = df.format(date);
        return epidemicService.getChinaSum(todayDate);
    }

    //获取各省疫情数据、新增数据
    @GetMapping("/province")
    public List<RespProvinceEpidemic> getProvinceEpidemic(){
        Date today=new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String todayDate = df.format(today);
        return epidemicService.getChinaProvince(todayDate);
    }

    //获取全国疫情累计总数据、累计新增数据
    @GetMapping("/statistics")
    public RespStatisticsEpidemic getStatisticsEpidemic(){
        return epidemicService.getStatisticsEpidemic();
    }

    //根据城市获取确诊、死亡、治愈、疑似人数，和对应的增加
    @GetMapping("/city")
    public ResChinaCity getCityEpidemic(@RequestParam(value = "city") String city){
        Date today=new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String todayDate = df.format(today);
        return epidemicService.getOneCity(city,todayDate);
    }

    //获取海外疫情数据
    @GetMapping("/oversea")
    public List<RespOverseaEpidemic> getOverseaEpidemic(){
        return overseaEpidemicService.getOversea();
    }

}
